package com.usefullc.crawler.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.crawler.domain.ActiveSliceInstance;
import com.usefullc.crawler.mapper.ActiveSliceInstanceMapper;
import com.usefullc.crawler.query.ActiveSliceInstanceQuery;
import com.usefullc.crawler.vo.ActiveSliceInstanceVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 爬虫活动切片实例服务类
 * @author: 星空
 * @date: 2023-07-12
 */
@Service
public class ActiveSliceInstanceService extends AbstractBizService<ActiveSliceInstanceMapper, ActiveSliceInstance, ActiveSliceInstanceQuery> {


    @Override
    protected QueryWrapper<ActiveSliceInstance> getQueryWrapper(ActiveSliceInstanceQuery query) {
        QueryWrapper<ActiveSliceInstance> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<ActiveSliceInstanceVo> findVoByPage(ActiveSliceInstanceQuery query){
        Pager<ActiveSliceInstance> page = this.findByPage(query);
        Pager<ActiveSliceInstanceVo> newPage = new Pager<>(page);
        List<ActiveSliceInstance> dataList = page.getDataList();
        List<ActiveSliceInstanceVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (ActiveSliceInstance activeSliceInstance : dataList) {
            ActiveSliceInstanceVo activeSliceInstanceVo = BeanUtils.beanCopy(activeSliceInstance, ActiveSliceInstanceVo.class);
            newDataList.add(activeSliceInstanceVo);
        }
        return newPage;
    }


}
